<?php
// +----------------------------------------------------------------------
// | KITEGO-Admin「开箱即用」「人人全栈」
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.kitego.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed KITEGO并不是自由软件，未经许可不能去掉KITEGO相关版权
// +----------------------------------------------------------------------
// | Author: KITEGO Team <bd@kitego.cn>
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\setting;

use app\adminapi\services\setting\AttachmentService;
use app\adminapi\validate\setting\AttachmentValidate;
use kitego\base\BaseController;
use think\App;

class AttachmentController extends BaseController
{
    public array $safeAction = [];

    private AttachmentService $service;

    public function __construct(App $app, AttachmentService $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }

    /**
     * 附件列表
     */
    public function attachmentList()
    {
        Validate(AttachmentValidate::class)->scene('attachmentList')->check($this->params);

        return $this->service->attachmentList($this->params);
    }

    /**
     * 附件移动
     */
    public function attachmentMove()
    {
        Validate(AttachmentValidate::class)->scene('attachmentMove')->check($this->params);

        return $this->service->attachmentMove($this->params['ids'], $this->params['cid']);
    }

    /**
     * 附件重命名
     */
    public function attachmentRename()
    {
        Validate(AttachmentValidate::class)->scene('attachmentRename')->check($this->params);

        return $this->service->attachmentRename($this->params['id'], $this->params['name'], $this->params['type']);
    }

    /**
     * 附件删除
     */
    public function attachmentDelete()
    {
        Validate(AttachmentValidate::class)->scene('attachmentDelete')->check($this->params);

        return $this->service->attachmentDelete($this->params['ids']);
    }

    /**
     * 后台附件上传
     */
    public function attachmentUpload()
    {
        Validate(AttachmentValidate::class)->scene('attachmentUpload')->check($this->params);

        return $this->service->attachmentUpload($this->params['cid'], $this->params['uploadType']);
    }
}